#include<vector>
#include<string>
#include<iostream>
#include<map>
#include "dmnbtext.h"


using namespace std;

int main(int argc, char * argv[]) {
	string filename = argv[1];
    DMNBText dmnbtext;
	dmnbtext.initClassifier(filename,false,20);
	dmnbtext.buildClassifier();
	map<int,int> sample;
	string text = "我是";
	dmnbtext.makeInstance(text, sample);
	int numClass = dmnbtext.getNumClass();
	int numWord = dmnbtext.getNumWord();
	double *prob = new double[numClass];
	int classidx = dmnbtext.getLogProbForTargetClass(sample, prob);
	for(int i=0; i<numClass; i++){
		cout << "i: " << i << dmnbtext.m_indexClassMap[i] << " prob:" << prob[i] << endl;
	}
	cout << classidx << ":" << dmnbtext.m_indexClassMap[classidx] << endl;

	for(int i=0; i<dmnbtext.m_instances.size(); i++){
		int human_idx = dmnbtext.m_instances[i][numWord];
		classidx = dmnbtext.getLogProbForTargetClass(dmnbtext.m_instances[i], prob);
		cout << human_idx << "\t" << dmnbtext.m_indexClassMap[human_idx] << "\t";
		cout << classidx << "\t" << dmnbtext.m_indexClassMap[classidx] << endl;
		//cout << "prob: " << prob[classidx] << endl;
	}

	cout << "test function predict......" << endl;
	cout << dmnbtext.predict("我明天还")  << endl;


	cout <<  "--------------------load_test--------------------" << endl;
	dmnbtext.saveClassifier("model.bin");
	
	DMNBText dmnbtext1;
	dmnbtext1.loadClassifier("model.bin");
	cout << dmnbtext1.predict("我明天还")  << endl;
	
	return 0;
}

